package com.tianpengtech.front.moduleA;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;
import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.common.plugin.shiro.ext.ShiroInterceptor;
import com.tianpengtech.common.util.ImageUtils;
import com.tianpengtech.common.util.JsonUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class H5Controller extends Controller {

    public void index() {
//        Subject subject = SecurityUtils.getSubject();
//        UsernamePasswordToken token = new UsernamePasswordToken("admin","12345") ;
//        subject.login(token);
        renderTemplate("index.html");
    }

    @Before(ShiroInterceptor.class)
    public void sshirohiro(){
        renderText("shiro test");
    }


    public void upload(){


        try {
            UploadFile file =  getFile("file");
            renderText(ImageUtils.upload(file,"/test/2017/03/b90fa460-d13b-400e-aca1-9a477cdf93ef.jpg","test"));
        } catch (ValidateException e) {
            renderJson(JsonUtil.printError(e.getMessage()));
        }
    }


    public void mqtt(){
        renderTemplate("mqtt.html");
    }

    public void logout(){
        Subject subject = SecurityUtils.getSubject() ;
        subject.logout();
        renderText("log out");
    }
}
